package com.xingxue.controller;

import com.xingxue.service.LoginService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.HashMap;

import javax.servlet.http.HttpSession;

/**
 * @author zgx at 2018/10/22 0022 上午 10:54
 */

@Controller
@RequestMapping("user")
public class LoginController {

    @Autowired
    LoginService loginService;


    @RequestMapping("/login")
    public ModelAndView login(@RequestParam HashMap<String,Object> param, HttpSession session){
        ModelAndView mv = new ModelAndView();
        HashMap<String, Object> login = this.loginService.login(param);
        session.setAttribute("login",login);
        mv.addObject("login",login);
        if(login != null){
            mv.setViewName("index");
        }else{
            mv.setViewName("login");
        }
        return mv;
    }


    @RequestMapping("/updatePwd")
    public ModelAndView updatePwd(@RequestParam HashMap<String,Object> param){
        ModelAndView mv = new ModelAndView();
        Integer integer = this.loginService.updatePwd(param);
        if(integer != null){
            mv.setViewName("index");
        }else{
            mv.setViewName("updatePassword");
        }
        return mv;
    }

}
